package test.v5;

import com.baishui.context.ApplicationContext;
import com.baishui.context.support.ClassPathXmlApplicationContext;
import com.baishui.service.v5.BaishuiV5Service;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import test.v5.util.MessageTracker;

import java.util.List;

public class Step08_ApplicationContextTest5 {
	
	@Before
	public void setUp(){
		MessageTracker.clearMsgs();
	}
	@Test
	public void testPlaceOrder() {
		
		ApplicationContext ctx = new ClassPathXmlApplicationContext("litespring-v5.xml");

		BaishuiV5Service baishuiV5Service = (BaishuiV5Service)ctx.getBean("baishuiAOP");
		
		Assert.assertNotNull(baishuiV5Service.getCar());
		Assert.assertNotNull(baishuiV5Service.getHouse());

		baishuiV5Service.placeOrder();
		
		List<String> msgs = MessageTracker.getMsgs();
		
		Assert.assertEquals(3, msgs.size());
		Assert.assertEquals("start tx", msgs.get(0));	
		Assert.assertEquals("place order", msgs.get(1));	
		Assert.assertEquals("commit tx", msgs.get(2));	
		
	}	
	
	
}
